package com.ocom.srvpaccess.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.human.EntityDeptInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.srvpaccess.dao.IDaoDeptInfo;
import com.ocom.srvpaccess.service.DeptInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DeptInfoServiceImpl extends ServiceImpl<IDaoDeptInfo, EntityDeptInfo> implements DeptInfoService {

    //注入deptInfo 持久层
    @Autowired
    private IDaoDeptInfo deptInfo;

    //5、根据deptID从部门信息表dept_info查出deptName；
    @DataSourceAspect(type= DataSourceEnum.PART_DB,companyId = "companyId")
    @Override
    public EntityDeptInfo getDeptInfo(Long companyId, Long deptId) {
        QueryWrapper<EntityDeptInfo> query = Wrappers.query();
        query.eq("com_id",companyId);
        query.eq("dept_id",deptId);
        query.last("limit 1");
        return deptInfo.selectOne(query);
    }
}
